let context = null
const initContext = (vue) => {
	context = vue;
}

const postEntityAsync = async (IdentifyId, IdentifyObject, token) => {
	let requrl = `${context.serverUrl}/PostEntity/PostEntity`;
	let result = await uni.request({
		url: requrl,
		method: "POST",
		header: {
			'Authorization': token,
			'platform': context.mobileDeviceInfo.platform,
			'uuid': context.mobileDeviceInfo.uuid,
			'model': context.mobileDeviceInfo.model,
		},
		data: {
			IdentifyId: IdentifyId,
			IdentifyObject: IdentifyObject
		}
	});
	return result;
}
//获取图片接口
const ImageReaderAsync = async(UserPhone,listImg,retContentType,token) =>{	
	let apiIdentifyId = "ImageReader";
	let objApiIdentify = {
		UserId:UserPhone,
		ImgIds:listImg,
		RetContentType:retContentType // 图片返回类型1：Base64字符串；2：src访问地址
	};	
	let strObject = JSON.stringify(objApiIdentify);
	let [error, result]  = await postEntityAsync(apiIdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		//console.log(result);
		return result.data;
	}
	return null;
}
//获取轮播图接口
const HPSlideImgsAsync = async (UserPhone,UpdateDateTime,token)=>{
	let IdentifyId = "HPSlideImgs";
	var objects = {
		'UserId':UserPhone,
		'UpdateDateTime':UpdateDateTime,
		'ClientType':context.ClientType,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}

const commService = {
	initContext,
	postEntityAsync,
	ImageReaderAsync,
	HPSlideImgsAsync,
}

export default commService
